package com.gadgets.framework.thread.event;

import com.gadgets.framework.common.event.GadgetsEvent;
import com.gadgets.framework.common.util.StringUtils;
import com.gadgets.framework.thread.hook.ThreadHook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author UncleXiu
 * @version V1.0.0
 * @data 2020-09-13
 * 
 */
@SuppressWarnings("rawtypes")
public abstract class GadgetsThreadTaskEvent extends GadgetsEvent {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    /**
     * 任务百分比
     */
    private Double percent;
    /**
     * 任务编号
     */
    private String taskNo;
    /**
     * 事件钩子
     */
    private ThreadHook threadHook;

    public Double getPercent() {
        return percent;
    }

    public void setPercent(Double percent) {
        this.percent = percent;
    }

    public ThreadHook getThreadHook() {
        return threadHook;
    }

    public void setThreadHook(ThreadHook threadHook) {
        this.threadHook = threadHook;
    }

    public String getTaskNo() {
        return taskNo;
    }

    public void setTaskNo(String taskNo) {
        this.taskNo = taskNo;
    }

    @SuppressWarnings("unchecked")
    public boolean excuteHook(){
        boolean excuteResult = false;
        try {
            if(null==threadHook){
                logger.warn("事件{}没有钩子需要执行",this.getClass().getName());
            } else {
                threadHook.excuteHook(this);
                excuteResult = true;
            }
        } catch (Exception e) {
            logger.error(StringUtils.formatExceptionStack(e));
        }
        return excuteResult;
    }

}
